.class public abstract Lorg/microemu/device/impl/InputMethodImpl;
.super Lorg/microemu/device/InputMethod;
.source "InputMethodImpl.java"

# interfaces
.implements Ljava/lang/Runnable;


# instance fields
.field private cancel:Z

.field protected lastButton:Lorg/microemu/device/impl/Button;

.field protected lastButtonCharIndex:I

.field protected resetKey:Z

.field private t:Ljava/lang/Thread;


# direct methods
.method public constructor <init>()V
    .locals 2

    .prologue
    .line 47
    invoke-direct {p0}, Lorg/microemu/device/InputMethod;-><init>()V

    .line 48
    const/4 v0, 0x0

    iput-object v0, p0, Lorg/microemu/device/impl/InputMethodImpl;->lastButton:Lorg/microemu/device/impl/Button;

    .line 49
    const/4 v0, -0x1

    iput v0, p0, Lorg/microemu/device/impl/InputMethodImpl;->lastButtonCharIndex:I

    .line 51
    const/4 v0, 0x0

    iput-boolean v0, p0, Lorg/microemu/device/impl/InputMethodImpl;->cancel:Z

    .line 52
    new-instance v0, Ljava/lang/Thread;

    const-string v1, "InputMethodThread"

    invoke-direct {v0, p0, v1}, Ljava/lang/Thread;-><init>(Ljava/lang/Runnable;Ljava/lang/String;)V

    iput-object v0, p0, Lorg/microemu/device/impl/InputMethodImpl;->t:Ljava/lang/Thread;

    .line 53
    iget-object v0, p0, Lorg/microemu/device/impl/InputMethodImpl;->t:Ljava/lang/Thread;

    const/4 v1, 0x1

    invoke-virtual {v0, v1}, Ljava/lang/Thread;->setDaemon(Z)V

    .line 54
    iget-object v0, p0, Lorg/microemu/device/impl/InputMethodImpl;->t:Ljava/lang/Thread;

    invoke-virtual {v0}, Ljava/lang/Thread;->start()V

    .line 55
    return-void
.end method


# virtual methods
.method public dispose()V
    .locals 1

    .prologue
    .line 59
    const/4 v0, 0x1

    iput-boolean v0, p0, Lorg/microemu/device/impl/InputMethodImpl;->cancel:Z

    .line 60
    monitor-enter p0

    .line 61
    :try_start_0
    invoke-virtual {p0}, Ljava/lang/Object;->notify()V

    .line 62
    monitor-exit p0

    .line 63
    return-void

    .line 62
    :catchall_0
    move-exception v0

    monitor-exit p0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v0
.end method

.method protected filterConstraints([C)[C
    .locals 8
    .parameter "chars"

    .prologue
    const/16 v7, 0x2d

    const/4 v6, 0x0

    .line 145
    array-length v4, p1

    new-array v3, v4, [C

    .line 148
    .local v3, result:[C
    const/4 v0, 0x0

    .local v0, i:I
    const/4 v1, 0x0

    .local v1, j:I
    :goto_0
    array-length v4, p1

    if-ge v0, v4, :cond_3

    .line 149
    iget-object v4, p0, Lorg/microemu/device/impl/InputMethodImpl;->inputMethodListener:Lorg/microemu/device/InputMethodListener;

    invoke-interface {v4}, Lorg/microemu/device/InputMethodListener;->getConstraints()I

    move-result v4

    const v5, 0xffff

    and-int/2addr v4, v5

    packed-switch v4, :pswitch_data_0

    .line 148
    :cond_0
    :goto_1
    :pswitch_0
    add-int/lit8 v0, v0, 0x1

    goto :goto_0

    .line 151
    :pswitch_1
    aget-char v4, p1, v0

    aput-char v4, v3, v1

    .line 152
    add-int/lit8 v1, v1, 0x1

    .line 153
    goto :goto_1

    .line 158
    :pswitch_2
    aget-char v4, p1, v0

    invoke-static {v4}, Ljava/lang/Character;->isDigit(C)Z

    move-result v4

    if-nez v4, :cond_1

    aget-char v4, p1, v0

    if-ne v4, v7, :cond_0

    .line 159
    :cond_1
    aget-char v4, p1, v0

    aput-char v4, v3, v1

    .line 160
    add-int/lit8 v1, v1, 0x1

    goto :goto_1

    .line 167
    :pswitch_3
    aget-char v4, p1, v0

    const/16 v5, 0xa

    if-eq v4, v5, :cond_0

    .line 168
    aget-char v4, p1, v0

    aput-char v4, v3, v1

    .line 169
    add-int/lit8 v1, v1, 0x1

    goto :goto_1

    .line 173
    :pswitch_4
    aget-char v4, p1, v0

    invoke-static {v4}, Ljava/lang/Character;->isDigit(C)Z

    move-result v4

    if-nez v4, :cond_2

    aget-char v4, p1, v0

    if-eq v4, v7, :cond_2

    aget-char v4, p1, v0

    const/16 v5, 0x2e

    if-ne v4, v5, :cond_0

    .line 174
    :cond_2
    aget-char v4, p1, v0

    aput-char v4, v3, v1

    .line 175
    add-int/lit8 v1, v1, 0x1

    goto :goto_1

    .line 180
    :cond_3
    if-eq v0, v1, :cond_4

    .line 181
    new-array v2, v1, [C

    .line 182
    .local v2, newresult:[C
    invoke-static {v3, v6, v2, v6, v1}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V

    .line 183
    move-object v3, v2

    .line 186
    .end local v2           #newresult:[C
    :cond_4
    return-object v3

    .line 149
    :pswitch_data_0
    .packed-switch 0x0
        :pswitch_1
        :pswitch_0
        :pswitch_2
        :pswitch_0
        :pswitch_3
        :pswitch_4
    .end packed-switch
.end method

.method protected filterInputMode([C)[C
    .locals 8
    .parameter "chars"

    .prologue
    const/4 v7, 0x0

    .line 190
    if-nez p1, :cond_0

    .line 191
    new-array v5, v7, [C

    .line 218
    :goto_0
    return-object v5

    .line 194
    :cond_0
    invoke-virtual {p0}, Lorg/microemu/device/impl/InputMethodImpl;->getInputMode()I

    move-result v1

    .line 195
    .local v1, inputMode:I
    array-length v5, p1

    new-array v4, v5, [C

    .line 198
    .local v4, result:[C
    const/4 v0, 0x0

    .local v0, i:I
    const/4 v2, 0x0

    .local v2, j:I
    :goto_1
    array-length v5, p1

    if-ge v0, v5, :cond_5

    .line 199
    const/4 v5, 0x2

    if-ne v1, v5, :cond_2

    .line 200
    aget-char v5, p1, v0

    invoke-static {v5}, Ljava/lang/Character;->toUpperCase(C)C

    move-result v5

    aput-char v5, v4, v2

    .line 201
    add-int/lit8 v2, v2, 0x1

    .line 198
    :cond_1
    :goto_2
    add-int/lit8 v0, v0, 0x1

    goto :goto_1

    .line 202
    :cond_2
    const/4 v5, 0x3

    if-ne v1, v5, :cond_3

    .line 203
    aget-char v5, p1, v0

    invoke-static {v5}, Ljava/lang/Character;->toLowerCase(C)C

    move-result v5

    aput-char v5, v4, v2

    .line 204
    add-int/lit8 v2, v2, 0x1

    goto :goto_2

    .line 205
    :cond_3
    const/4 v5, 0x1

    if-ne v1, v5, :cond_1

    .line 206
    aget-char v5, p1, v0

    invoke-static {v5}, Ljava/lang/Character;->isDigit(C)Z

    move-result v5

    if-nez v5, :cond_4

    aget-char v5, p1, v0

    const/16 v6, 0x2d

    if-eq v5, v6, :cond_4

    aget-char v5, p1, v0

    const/16 v6, 0x2e

    if-ne v5, v6, :cond_1

    .line 207
    :cond_4
    aget-char v5, p1, v0

    aput-char v5, v4, v2

    .line 208
    add-int/lit8 v2, v2, 0x1

    goto :goto_2

    .line 212
    :cond_5
    if-eq v0, v2, :cond_6

    .line 213
    new-array v3, v2, [C

    .line 214
    .local v3, newresult:[C
    invoke-static {v4, v7, v3, v7, v2}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V

    .line 215
    move-object v4, v3

    .end local v3           #newresult:[C
    :cond_6
    move-object v5, v4

    .line 218
    goto :goto_0
.end method

.method protected insertText(Ljava/lang/String;)V
    .locals 6
    .parameter "str"

    .prologue
    .line 116
    invoke-virtual {p1}, Ljava/lang/String;->length()I

    move-result v3

    if-lez v3, :cond_3

    .line 117
    iget-object v3, p0, Lorg/microemu/device/impl/InputMethodImpl;->inputMethodListener:Lorg/microemu/device/InputMethodListener;

    invoke-interface {v3}, Lorg/microemu/device/InputMethodListener;->getCaretPosition()I

    move-result v0

    .line 118
    .local v0, caret:I
    const-string v2, ""

    .line 119
    .local v2, tmp:Ljava/lang/String;
    monitor-enter p0

    .line 120
    :try_start_0
    iget-object v3, p0, Lorg/microemu/device/impl/InputMethodImpl;->lastButton:Lorg/microemu/device/impl/Button;

    if-eqz v3, :cond_0

    .line 121
    add-int/lit8 v0, v0, 0x1

    .line 122
    const/4 v3, 0x0

    iput-object v3, p0, Lorg/microemu/device/impl/InputMethodImpl;->lastButton:Lorg/microemu/device/impl/Button;

    .line 123
    const/4 v3, -0x1

    iput v3, p0, Lorg/microemu/device/impl/InputMethodImpl;->lastButtonCharIndex:I

    .line 125
    :cond_0
    if-lez v0, :cond_1

    .line 126
    new-instance v3, Ljava/lang/StringBuffer;

    invoke-direct {v3}, Ljava/lang/StringBuffer;-><init>()V

    invoke-virtual {v3, v2}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    iget-object v4, p0, Lorg/microemu/device/impl/InputMethodImpl;->inputMethodListener:Lorg/microemu/device/InputMethodListener;

    invoke-interface {v4}, Lorg/microemu/device/InputMethodListener;->getText()Ljava/lang/String;

    move-result-object v4

    const/4 v5, 0x0

    invoke-virtual {v4, v5, v0}, Ljava/lang/String;->substring(II)Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v3, v4}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v2

    .line 128
    :cond_1
    new-instance v3, Ljava/lang/StringBuffer;

    invoke-direct {v3}, Ljava/lang/StringBuffer;-><init>()V

    invoke-virtual {v3, v2}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    invoke-virtual {v3, p1}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v2

    .line 129
    .restart local v2       #tmp:Ljava/lang/String;
    iget-object v3, p0, Lorg/microemu/device/impl/InputMethodImpl;->inputMethodListener:Lorg/microemu/device/InputMethodListener;

    invoke-interface {v3}, Lorg/microemu/device/InputMethodListener;->getText()Ljava/lang/String;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/String;->length()I

    move-result v3

    if-ge v0, v3, :cond_2

    .line 130
    new-instance v3, Ljava/lang/StringBuffer;

    invoke-direct {v3}, Ljava/lang/StringBuffer;-><init>()V

    invoke-virtual {v3, v2}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    iget-object v4, p0, Lorg/microemu/device/impl/InputMethodImpl;->inputMethodListener:Lorg/microemu/device/InputMethodListener;

    invoke-interface {v4}, Lorg/microemu/device/InputMethodListener;->getText()Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v4, v0}, Ljava/lang/String;->substring(I)Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v3, v4}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v2

    .line 132
    .restart local v2       #tmp:Ljava/lang/String;
    :cond_2
    invoke-virtual {p1}, Ljava/lang/String;->length()I

    move-result v3

    add-int/2addr v0, v3

    .line 133
    monitor-exit p0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 134
    iget-object v3, p0, Lorg/microemu/device/impl/InputMethodImpl;->inputMethodListener:Lorg/microemu/device/InputMethodListener;

    invoke-interface {v3}, Lorg/microemu/device/InputMethodListener;->getConstraints()I

    move-result v3

    invoke-static {v2, v3}, Lorg/microemu/device/impl/InputMethodImpl;->validate(Ljava/lang/String;I)Z

    move-result v3

    if-nez v3, :cond_4

    .line 142
    .end local v0           #caret:I
    .end local v2           #tmp:Ljava/lang/String;
    :cond_3
    :goto_0
    return-void

    .line 133
    .restart local v0       #caret:I
    .restart local v2       #tmp:Ljava/lang/String;
    :catchall_0
    move-exception v3

    :try_start_1
    monitor-exit p0
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    throw v3

    .line 137
    :cond_4
    new-instance v1, Lorg/microemu/device/InputMethodEvent;

    const/4 v3, 0x2

    invoke-direct {v1, v3, v0, v2}, Lorg/microemu/device/InputMethodEvent;-><init>(IILjava/lang/String;)V

    .line 138
    .local v1, event:Lorg/microemu/device/InputMethodEvent;
    iget-object v3, p0, Lorg/microemu/device/impl/InputMethodImpl;->inputMethodListener:Lorg/microemu/device/InputMethodListener;

    invoke-interface {v3, v1}, Lorg/microemu/device/InputMethodListener;->inputMethodTextChanged(Lorg/microemu/device/InputMethodEvent;)V

    .line 139
    new-instance v1, Lorg/microemu/device/InputMethodEvent;

    .end local v1           #event:Lorg/microemu/device/InputMethodEvent;
    const/4 v3, 0x1

    invoke-direct {v1, v3, v0, v2}, Lorg/microemu/device/InputMethodEvent;-><init>(IILjava/lang/String;)V

    .line 140
    .restart local v1       #event:Lorg/microemu/device/InputMethodEvent;
    iget-object v3, p0, Lorg/microemu/device/impl/InputMethodImpl;->inputMethodListener:Lorg/microemu/device/InputMethodListener;

    invoke-interface {v3, v1}, Lorg/microemu/device/InputMethodListener;->caretPositionChanged(Lorg/microemu/device/InputMethodEvent;)V

    goto :goto_0
.end method

.method public pointerDragged(II)V
    .locals 1
    .parameter "x"
    .parameter "y"

    .prologue
    .line 110
    invoke-static {}, Lorg/microemu/device/DeviceFactory;->getDevice()Lorg/microemu/device/Device;

    move-result-object v0

    invoke-interface {v0}, Lorg/microemu/device/Device;->hasPointerMotionEvents()Z

    move-result v0

    if-eqz v0, :cond_0

    .line 111
    invoke-static {}, Lorg/microemu/MIDletBridge;->getMIDletAccess()Lorg/microemu/MIDletAccess;

    move-result-object v0

    invoke-virtual {v0}, Lorg/microemu/MIDletAccess;->getDisplayAccess()Lorg/microemu/DisplayAccess;

    move-result-object v0

    invoke-interface {v0, p1, p2}, Lorg/microemu/DisplayAccess;->pointerDragged(II)V

    .line 113
    :cond_0
    return-void
.end method

.method public pointerPressed(II)V
    .locals 1
    .parameter "x"
    .parameter "y"

    .prologue
    .line 98
    invoke-static {}, Lorg/microemu/device/DeviceFactory;->getDevice()Lorg/microemu/device/Device;

    move-result-object v0

    invoke-interface {v0}, Lorg/microemu/device/Device;->hasPointerEvents()Z

    move-result v0

    if-eqz v0, :cond_0

    .line 99
    invoke-static {}, Lorg/microemu/MIDletBridge;->getMIDletAccess()Lorg/microemu/MIDletAccess;

    move-result-object v0

    invoke-virtual {v0}, Lorg/microemu/MIDletAccess;->getDisplayAccess()Lorg/microemu/DisplayAccess;

    move-result-object v0

    invoke-interface {v0, p1, p2}, Lorg/microemu/DisplayAccess;->pointerPressed(II)V

    .line 101
    :cond_0
    return-void
.end method

.method public pointerReleased(II)V
    .locals 1
    .parameter "x"
    .parameter "y"

    .prologue
    .line 104
    invoke-static {}, Lorg/microemu/device/DeviceFactory;->getDevice()Lorg/microemu/device/Device;

    move-result-object v0

    invoke-interface {v0}, Lorg/microemu/device/Device;->hasPointerEvents()Z

    move-result v0

    if-eqz v0, :cond_0

    .line 105
    invoke-static {}, Lorg/microemu/MIDletBridge;->getMIDletAccess()Lorg/microemu/MIDletAccess;

    move-result-object v0

    invoke-virtual {v0}, Lorg/microemu/MIDletAccess;->getDisplayAccess()Lorg/microemu/DisplayAccess;

    move-result-object v0

    invoke-interface {v0, p1, p2}, Lorg/microemu/DisplayAccess;->pointerReleased(II)V

    .line 107
    :cond_0
    return-void
.end method

.method public run()V
    .locals 4

    .prologue
    .line 68
    :goto_0
    iget-boolean v2, p0, Lorg/microemu/device/impl/InputMethodImpl;->cancel:Z

    if-nez v2, :cond_1

    .line 70
    const/4 v2, 0x1

    :try_start_0
    iput-boolean v2, p0, Lorg/microemu/device/impl/InputMethodImpl;->resetKey:Z

    .line 71
    monitor-enter p0
    :try_end_0
    .catch Ljava/lang/InterruptedException; {:try_start_0 .. :try_end_0} :catch_0

    .line 72
    const-wide/16 v2, 0x5dc

    :try_start_1
    invoke-virtual {p0, v2, v3}, Ljava/lang/Object;->wait(J)V

    .line 73
    monitor-exit p0
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_1

    .line 76
    :goto_1
    monitor-enter p0

    .line 77
    :try_start_2
    iget-boolean v2, p0, Lorg/microemu/device/impl/InputMethodImpl;->resetKey:Z

    if-eqz v2, :cond_0

    iget-object v2, p0, Lorg/microemu/device/impl/InputMethodImpl;->lastButton:Lorg/microemu/device/impl/Button;

    if-eqz v2, :cond_0

    iget-object v2, p0, Lorg/microemu/device/impl/InputMethodImpl;->inputMethodListener:Lorg/microemu/device/InputMethodListener;

    if-eqz v2, :cond_0

    .line 78
    iget-object v2, p0, Lorg/microemu/device/impl/InputMethodImpl;->inputMethodListener:Lorg/microemu/device/InputMethodListener;

    invoke-interface {v2}, Lorg/microemu/device/InputMethodListener;->getCaretPosition()I

    move-result v2

    add-int/lit8 v0, v2, 0x1

    .line 79
    .local v0, caret:I
    iget-object v2, p0, Lorg/microemu/device/impl/InputMethodImpl;->inputMethodListener:Lorg/microemu/device/InputMethodListener;

    invoke-interface {v2}, Lorg/microemu/device/InputMethodListener;->getText()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/String;->length()I

    move-result v2

    if-gt v0, v2, :cond_0

    .line 80
    const/4 v2, 0x0

    iput-object v2, p0, Lorg/microemu/device/impl/InputMethodImpl;->lastButton:Lorg/microemu/device/impl/Button;

    .line 81
    const/4 v2, -0x1

    iput v2, p0, Lorg/microemu/device/impl/InputMethodImpl;->lastButtonCharIndex:I

    .line 82
    new-instance v1, Lorg/microemu/device/InputMethodEvent;

    const/4 v2, 0x1

    iget-object v3, p0, Lorg/microemu/device/impl/InputMethodImpl;->inputMethodListener:Lorg/microemu/device/InputMethodListener;

    invoke-interface {v3}, Lorg/microemu/device/InputMethodListener;->getText()Ljava/lang/String;

    move-result-object v3

    invoke-direct {v1, v2, v0, v3}, Lorg/microemu/device/InputMethodEvent;-><init>(IILjava/lang/String;)V

    .line 83
    .local v1, event:Lorg/microemu/device/InputMethodEvent;
    iget-object v2, p0, Lorg/microemu/device/impl/InputMethodImpl;->inputMethodListener:Lorg/microemu/device/InputMethodListener;

    invoke-interface {v2, v1}, Lorg/microemu/device/InputMethodListener;->caretPositionChanged(Lorg/microemu/device/InputMethodEvent;)V

    .line 86
    .end local v0           #caret:I
    .end local v1           #event:Lorg/microemu/device/InputMethodEvent;
    :cond_0
    monitor-exit p0

    goto :goto_0

    :catchall_0
    move-exception v2

    monitor-exit p0
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    throw v2

    .line 73
    :catchall_1
    move-exception v2

    :try_start_3
    monitor-exit p0
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_1

    :try_start_4
    throw v2
    :try_end_4
    .catch Ljava/lang/InterruptedException; {:try_start_4 .. :try_end_4} :catch_0

    .line 74
    :catch_0
    move-exception v2

    goto :goto_1

    .line 88
    :cond_1
    return-void
.end method

.method public setInputMethodListener(Lorg/microemu/device/InputMethodListener;)V
    .locals 1
    .parameter "l"

    .prologue
    .line 91
    invoke-super {p0, p1}, Lorg/microemu/device/InputMethod;->setInputMethodListener(Lorg/microemu/device/InputMethodListener;)V

    .line 93
    const/4 v0, 0x0

    iput-object v0, p0, Lorg/microemu/device/impl/InputMethodImpl;->lastButton:Lorg/microemu/device/impl/Button;

    .line 94
    const/4 v0, -0x1

    iput v0, p0, Lorg/microemu/device/impl/InputMethodImpl;->lastButtonCharIndex:I

    .line 95
    return-void
.end method
